<?php

class FP_Controller_Action extends Zend_Controller_Action implements FP_Controller_Action_Interface {

    protected $_layout = null;

    protected $_current_route = null;
    protected $_current_uri   = null;

    protected $_norefer = array();

    public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array()){
	parent::__construct($request, $response, $invokeArgs);

	Zend_Layout::getMvcInstance()->setLayoutPath(BASE_DIR . 'app/views/layouts');

	$layout = ($this->_layout) ? $this->_layout : $request->getControllerName();
	Zend_Layout::getMvcInstance()->setLayout($layout);

	$this->view->current_uri   = $request->getRequestUri();
	$this->view->current_route = Zend_Controller_Front::getInstance()->getRouter()->getCurrentRouteName();

    }

    public function getActions(){
	$actions = array();

	$methods = get_class_methods($this);

	foreach ($methods as $method){
	    if (preg_match('/^(.*)Action$/', $method, $matches)){
		$actions[] = $matches[1];
	    }
	}

	return $actions;
    }

    public function getNoRefer(){
	return $this->_norefer;
    }

    public function setLayout($pLayout){
	Zend_Layout::getMvcInstance()->setLayout($pLayout);
    }

    public function disableView(){
	$this->_helper->layout->disableLayout();
	$this->_helper->viewRenderer->setNoRender();
    }

    public function disableLayout(){
	$this->_helper->Layout->disableLayout();
    }

    protected function gotoReferer($pDefaultUri=null){
	$this->_helper->Referer->gotoReferer($pDefaultUri);
    }

    protected function resolveRoute($pRouteName, array $pParams=array()){
	$route = Zend_Controller_Front::getInstance()->getRouter()->getRoute($pRouteName);
	return FP_Application::get('server') . '/' . ltrim($route->assemble($pParams), '/');
    }

    protected function notifications($pMessage, $pType='info'){
      $this->view->this->notifications($pMessage, $pType);
   }

    protected function gotoRoute($pRouteName, array $pParams=array()){
	$this->_helper->Redirector->gotoRoute($pParams, $pRouteName);
    }

    protected function getCleanParams(){
	$params = $this->_getAllParams();
	unset($params['controller']);
	unset($params['action']);
	unset($params['module']);
	return $params;
    }
}

?>